<?php
// +----------------------------------------------------------------------
// | author: thinkphp
// +----------------------------------------------------------------------

namespace app\api\lists\cart;

use app\api\lists\BaseApiDataLists;
use app\common\enum\YesNoEnum;
use app\common\model\user\Cart;

/**
 * 文章收藏列表
 * Class ArticleCollectLists
 * @package app\api\lists\article
 */
class CartLists extends BaseApiDataLists
{

    /**
     * @notes 获取列表
     * @return array
     */
    public function lists(): array
    {
        $field = "c.id as cart_id,c.line_id,c.price_id,c.adult_count,c.child_count,c.selected,c.travel_date,l.title,l.line_image,p.price";

        $lists = (new Cart())->alias('c')
            ->join('line l', 'l.id = c.line_id')
            ->join('line_price p', 'p.id = c.price_id')
            ->field($field)
            ->where([
                'c.user_id' => $this->userId,
                'l.status' => YesNoEnum::YES,
                'p.status' => YesNoEnum::YES,
            ])
            ->order('c.create_time desc')
            ->limit($this->limitOffset, $this->limitLength)
            ->select()->toArray();
//        var_dump($lists);
//        foreach ($lists as &$item) {
//            $item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
//        }
        return $lists;
    }


    /**
     * @notes 获取数量
     * @return int
     */
    public function count(): int
    {
        return (new Cart())->alias('c')
            ->join('line l', 'l.id = c.line_id')
            ->join('line_price p', 'p.id = c.price_id')
            ->where([
                'c.user_id' => $this->userId,
                'l.status' => YesNoEnum::YES,
                'p.status' => YesNoEnum::YES,
            ])
            ->count();
    }
}